﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimCMS.Common
{
    public class PageUnit<T> : List<T>
    {
        public int DataCount { get; set; }//总记录数
        public int PageCount { get; set; }//总页数
        public int PageNo { get; set; }//当前页码
        public int PageSize { get; set; }//每页显示记录




        public bool HasPreviousPage
        {
            get
            {
                return PageNo > 1;
            }
        }


        public bool HasNextPage
        {
            get
            {
                return PageNo < this.PageCount;
            }
        }


        public PageUnit(List<T> datalist, int pageSize, int pageNo)
        {
            this.PageSize = pageSize;
            this.PageNo = pageNo;
            this.DataCount = datalist.Count;
            this.PageCount = (int)Math.Ceiling((decimal)this.DataCount / pageSize);
            this.AddRange(datalist.Skip((pageNo - 1) * pageSize).Take(pageSize));
        }
    }
}
